<?php

	$db_name="website"; // Database name 

	include "../conf/config.php";
	$result = mysql_connect($host,$granted_user,$granted_mdp)or die("impossible de se connecter"); 
	$result = mysql_select_db("$db_name")or die("ne peut selectioner DB");

	if (!$result) {
 		$message  = 'Requête invalide : ' . mysql_error() . "\n";
		$message .= 'Requête complète : ' . $query;
		die($message);
		echo $message;
	}

	if (isset($_POST['modify'])) {

		if (isset($_POST['new_skill']) && isset($_POST['old_skill']) &&
			is_array($_POST['new_skill']) && is_array($_POST['old_skill']) ) {

			$new_skill = $_POST['new_skill'];
			$old_skill = $_POST['old_skill'];

			foreach ($new_skill as $key => $value) 
			{
				//echo $new_skill[$key]." - ";
				//echo $old_skill[$key]."<br>";
				//$verif = is_int($new_skill[$key]);
				//echo $verif. "<br>";

				if (isset($old_skill[$key]) && is_int($value + 0) && $value != $old_skill[$key]) 
				{
					$sql = "UPDATE evo SET progression='".$value."' WHERE id_evo='".$key."';";
					$ok = mysql_query($sql); 
				}
				
			}
		}
	}

	$_SESSION['user']['message'] = "Demande effectuée.";
	$location = 'index.php';
	header('Location: ' . $location);
?>